stripping cdata from the value

oroce лет %!s(int64=8): %!d(string=назад)
Родитель
Сommit
8afca6fed0
3 измененных файлов с 176 добавлено и 1 удалено
  1. 10 1
      app/models/agents/website_agent.rb
  2. 131 0
      spec/data_fixtures/cdata_rss.atom
  3. 35 0
      spec/models/agents/website_agent_spec.rb

+ 10 - 1
app/models/agents/website_agent.rb

@@ -46,6 +46,8 @@ module Agents
46 46
 
47 47
       Beware that when parsing an XML document (i.e. `type` is `xml`) using `xpath` expressions all namespaces are stripped from the document unless a toplevel option `use_namespaces` is set to true.
48 48
 
49
+      If the extracted value contains `<![CDATA[content]]` you can get the `content` part if you set `strip_cdata` to true.
50
+
49 51
       # Scraping JSON
50 52
 
51 53
       When parsing JSON, these sub-hashes specify [JSONPaths](http://goessner.net/articles/JsonPath/) to the values that you care about.  For example:
@@ -439,7 +441,14 @@ module Agents
439 441
         case nodes
440 442
         when Nokogiri::XML::NodeSet
441 443
           result = nodes.map { |node|
442
-            case value = node.xpath(extraction_details['value'] || '.')
444
+            value = node.xpath(extraction_details['value'] || '.')
445
+            if extraction_details['strip_cdata']
446
+              child = value.first
447
+              if child.cdata?
448
+                value = child.text
449
+              end
450
+            end
451
+            case value
443 452
             when Float
444 453
               # Node#xpath() returns any numeric value as float;
445 454
               # convert it to integer as appropriate.

+ 131 - 0
spec/data_fixtures/cdata_rss.atom

@@ -0,0 +1,131 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
3
+  <link rel="self" type="application/atom+xml" href="http://rainmeter.net/forum/feed.php" />
4
+  <title>Rainmeter Forums</title>
5
+  <link href="http://rainmeter.net/forum/index.php" />
6
+  <updated>2015-10-11T14:52:35+00:00</updated>
7
+  <author>
8
+    <name><![CDATA[Rainmeter Forums]]></name>
9
+  </author>
10
+  <id>http://rainmeter.net/forum/feed.php</id>
11
+  <entry>
12
+    <author>
13
+      <name><![CDATA[supergergo]]></name>
14
+    </author>
15
+    <updated>2015-10-11T14:52:35+00:00</updated>
16
+    <published>2015-10-11T14:52:35+00:00</published>
17
+    <id>http://rainmeter.net/forum/viewtopic.php?t=21984&amp;p=116390#p116390</id>
18
+    <link href="http://rainmeter.net/forum/viewtopic.php?t=21984&amp;p=116390#p116390" />
19
+    <title type="html"><![CDATA[Help: Rainmeter Skins • Re: Cannot change font for Simple Launcher]]></title>
20
+    <category term="Help: Rainmeter Skins" scheme="http://rainmeter.net/forum/viewforum.php?f=5" label="Help: Rainmeter Skins" />
21
+    <content type="html" xml:base="http://rainmeter.net/forum/viewtopic.php?t=21984&amp;p=116390#p116390"><![CDATA[<div class="quotewrapper"><div class="quotetitle">jsmorley wrote:</div><div class="quotecontent"><br />You don't use the file name of the font, you use the internal font name.<br /><br /><span style="background: none repeat scroll 0 0 #FFFFFF; border: 1px solid #869AA8; color: #2E8B57; display: inline; font-family: Monaco,'Andale Mono','Courier New',Courier,monospace; font-size: 1em; font-style: normal; line-height: 1.3em; padding: 0 3px;">FontFace=ITC Avant Garde Pro XLt</span><br /><br /><div class="attachwrapper">1.jpg</div><br /></div></div><br /><br />Thank you!!<p>Statistics: Posted by <a href="http://rainmeter.net/forum/memberlist.php?mode=viewprofile&amp;u=35297">supergergo</a> — 29 minutes ago</p><hr />]]></content>
22
+  </entry>
23
+  <entry>
24
+    <author>
25
+      <name><![CDATA[redsaph]]></name>
26
+    </author>
27
+    <updated>2015-10-11T13:51:44+00:00</updated>
28
+    <published>2015-10-11T13:51:44+00:00</published>
29
+    <id>http://rainmeter.net/forum/viewtopic.php?t=21411&amp;p=116389#p116389</id>
30
+    <link href="http://rainmeter.net/forum/viewtopic.php?t=21411&amp;p=116389#p116389" />
31
+    <title type="html"><![CDATA[Plugins &amp; Addons • Re: Plugin: ColorExtract]]></title>
32
+    <category term="Plugins &amp; Addons" scheme="http://rainmeter.net/forum/viewforum.php?f=18" label="Plugins &amp; Addons" />
33
+    <content type="html" xml:base="http://rainmeter.net/forum/viewtopic.php?t=21411&amp;p=116389#p116389"><![CDATA[This is pretty great! The things we can do with this plugin...  <img src="http://rainmeter.net/forum/images/smilies/yikes.gif" alt=":o" title="Shocked" /><p>Statistics: Posted by <a href="http://rainmeter.net/forum/memberlist.php?mode=viewprofile&amp;u=28432">redsaph</a> — Today, 1:51 pm</p><hr />]]></content>
34
+  </entry>
35
+  <entry>
36
+    <author>
37
+      <name><![CDATA[jsmorley]]></name>
38
+    </author>
39
+    <updated>2015-10-11T13:36:51+00:00</updated>
40
+    <published>2015-10-11T13:36:51+00:00</published>
41
+    <id>http://rainmeter.net/forum/viewtopic.php?t=21984&amp;p=116388#p116388</id>
42
+    <link href="http://rainmeter.net/forum/viewtopic.php?t=21984&amp;p=116388#p116388" />
43
+    <title type="html"><![CDATA[Help: Rainmeter Skins • Re: Cannot change font for Simple Launcher]]></title>
44
+    <category term="Help: Rainmeter Skins" scheme="http://rainmeter.net/forum/viewforum.php?f=5" label="Help: Rainmeter Skins" />
45
+    <content type="html" xml:base="http://rainmeter.net/forum/viewtopic.php?t=21984&amp;p=116388#p116388"><![CDATA[You don't use the file name of the font, you use the internal font name.<br /><br /><span style="background: none repeat scroll 0 0 #FFFFFF; border: 1px solid #869AA8; color: #2E8B57; display: inline; font-family: Monaco,'Andale Mono','Courier New',Courier,monospace; font-size: 1em; font-style: normal; line-height: 1.3em; padding: 0 3px;">FontFace=ITC Avant Garde Pro XLt</span><br /><br /><div class="attachwrapper">1.jpg</div><p>Statistics: Posted by <a href="http://rainmeter.net/forum/memberlist.php?mode=viewprofile&amp;u=85">jsmorley</a> — Today, 1:36 pm</p><hr />]]></content>
46
+  </entry>
47
+  <entry>
48
+    <author>
49
+      <name><![CDATA[xlr8r_]]></name>
50
+    </author>
51
+    <updated>2015-10-11T13:35:15+00:00</updated>
52
+    <published>2015-10-11T13:35:15+00:00</published>
53
+    <id>http://rainmeter.net/forum/viewtopic.php?t=21939&amp;p=116387#p116387</id>
54
+    <link href="http://rainmeter.net/forum/viewtopic.php?t=21939&amp;p=116387#p116387" />
55
+    <title type="html"><![CDATA[Tips &amp; Tricks • Re: Working with the HWiNFO plugin]]></title>
56
+    <category term="Tips &amp; Tricks" scheme="http://rainmeter.net/forum/viewforum.php?f=15" label="Tips &amp; Tricks" />
57
+    <content type="html" xml:base="http://rainmeter.net/forum/viewtopic.php?t=21939&amp;p=116387#p116387"><![CDATA[again: one more<p>Statistics: Posted by <a href="http://rainmeter.net/forum/memberlist.php?mode=viewprofile&amp;u=35276">xlr8r_</a> — Today, 1:35 pm</p><hr />]]></content>
58
+  </entry>
59
+  <entry>
60
+    <author>
61
+      <name><![CDATA[supergergo]]></name>
62
+    </author>
63
+    <updated>2015-10-11T13:27:56+00:00</updated>
64
+    <published>2015-10-11T13:27:56+00:00</published>
65
+    <id>http://rainmeter.net/forum/viewtopic.php?t=21984&amp;p=116386#p116386</id>
66
+    <link href="http://rainmeter.net/forum/viewtopic.php?t=21984&amp;p=116386#p116386" />
67
+    <title type="html"><![CDATA[Help: Rainmeter Skins • Cannot change font for Simple Launcher]]></title>
68
+    <category term="Help: Rainmeter Skins" scheme="http://rainmeter.net/forum/viewforum.php?f=5" label="Help: Rainmeter Skins" />
69
+    <content type="html" xml:base="http://rainmeter.net/forum/viewtopic.php?t=21984&amp;p=116386#p116386"><![CDATA[Hi,<br />I simply cannot change the font for this skin. I tried the @Resources folder in the skin's root, but nothing, I also tried to install the font, but still, nothing. <br /><br />Here is a snip of my code:<br />[APP1]<br />Meter=STRING<br />X=0<br />Y=0<br />FontColor=255, 255, 255, 1000<br />FontSize=40<br />FontFace=ITCAvantGardePro-XLt<br />SolidColor=0,0,0,1<br />StringStyle=NORMAL<br />StringAlign=LEFT<br />AntiAlias=1<br />Text=&quot;University&quot;<br />LeftMouseUpAction=!Execute [&quot;C:\Users\G\Documents\Uni&quot;]<br /><br />I also tried to use other variations of the font, but still nothing happens when I save and hit refresh. Even if it says the font's name at FontFace, it does not change.<br /><br />Link for the launcher: <!-- m --><a class="postlink" href="http://danieliop.deviantart.com/art/Simple-RM-Launcher-216478809">http://danieliop.deviantart.com/art/Sim ... -216478809</a><!-- m --><p>Statistics: Posted by <a href="http://rainmeter.net/forum/memberlist.php?mode=viewprofile&amp;u=35297">supergergo</a> — Today, 1:27 pm</p><hr />]]></content>
70
+  </entry>
71
+  <entry>
72
+    <author>
73
+      <name><![CDATA[balala]]></name>
74
+    </author>
75
+    <updated>2015-10-11T08:27:55+00:00</updated>
76
+    <published>2015-10-11T08:27:55+00:00</published>
77
+    <id>http://rainmeter.net/forum/viewtopic.php?t=21982&amp;p=116381#p116381</id>
78
+    <link href="http://rainmeter.net/forum/viewtopic.php?t=21982&amp;p=116381#p116381" />
79
+    <title type="html"><![CDATA[Help: Rainmeter Skins • Re: Test if Today is Between 2 Dates]]></title>
80
+    <category term="Help: Rainmeter Skins" scheme="http://rainmeter.net/forum/viewforum.php?f=5" label="Help: Rainmeter Skins" />
81
+    <content type="html" xml:base="http://rainmeter.net/forum/viewtopic.php?t=21982&amp;p=116381#p116381"><![CDATA[If I'm not wrong your bangs are wrong, because you want to show/hide a group of meters. For that, you have to use the !ShowMeterGroup/!HideMeterGroup bangs, instead of !ShowGroup/!HideGroup. The last pair will show/hide a group of active skins, while the !ShowMeterGroup/!HideMeterGroup will show/hide a group of meters. On your posted code, One is a group of meters (it contains the [Boo] meter). So, replace the [MeasureDate] measure with something like this:<br /><div><div class="codetitle"><b>Code:</b> </div><div class="codecontent"><code>&#91;MeasureDate&#93;<br />Measure=Time<br />Format=%#m.%d<br />IfCondition=(MeasureDate &gt;= 12.02) &amp;&amp; (MeasureDate &lt;= 12.25)<br />IfTrueAction=&#91;!ShowMeterGroup One&#93;<br />IfFalseAction=&#91;!HideMeterGroup One&#93;</code></div></div><p>Statistics: Posted by <a href="http://rainmeter.net/forum/memberlist.php?mode=viewprofile&amp;u=7491">balala</a> — Today, 8:27 am</p><hr />]]></content>
82
+  </entry>
83
+  <entry>
84
+    <author>
85
+      <name><![CDATA[bill98]]></name>
86
+    </author>
87
+    <updated>2015-10-11T14:02:43+00:00</updated>
88
+    <published>2015-10-11T07:36:57+00:00</published>
89
+    <id>http://rainmeter.net/forum/viewtopic.php?t=21982&amp;p=116380#p116380</id>
90
+    <link href="http://rainmeter.net/forum/viewtopic.php?t=21982&amp;p=116380#p116380" />
91
+    <title type="html"><![CDATA[Help: Rainmeter Skins • Re: Test if Today is Between 2 Dates]]></title>
92
+    <category term="Help: Rainmeter Skins" scheme="http://rainmeter.net/forum/viewforum.php?f=5" label="Help: Rainmeter Skins" />
93
+    <content type="html" xml:base="http://rainmeter.net/forum/viewtopic.php?t=21982&amp;p=116380#p116380"><![CDATA[Thanks!  I must have something else wrong, because it always shows the group/Image.<br /><br /><div><div class="codetitle"><b>Code:</b> </div><div class="codecontent"><code>&#91;Variables&#93;<br />@Include1=#@#VariablesM2.inc<br />@Include2=#@#FloatingImage.inc<br />IN=1<br />;Holiday<br /><br />&#91;mIName&#93;<br />Measure=String<br />String=#IN#<br />DynamicVariables=1<br />RegExpSubstitute=1<br />Substitute=&quot;^1$&quot;:&quot;#1IName#&quot;,&quot;^2$&quot;:&quot;#2IName#&quot;,&quot;^3$&quot;:&quot;#3IName#&quot;,&quot;^4$&quot;:&quot;#4IName#&quot;,&quot;^5$&quot;:&quot;#5IName#&quot;,&quot;^6$&quot;:&quot;#6IName#&quot;,&quot;^7$&quot;:&quot;#7IName#&quot;,&quot;^8$&quot;:&quot;#8IName#&quot;,&quot;^9$&quot;:&quot;#9IName#&quot;,&quot;^10$&quot;:&quot;#10IName#&quot;<br /><br />&#91;mSizex&#93;<br />Measure=String<br />String=#IN#<br />DynamicVariables=1<br />RegExpSubstitute=1<br />Substitute=&quot;^1$&quot;:&quot;#1Sizex#&quot;,&quot;^2$&quot;:&quot;#2Sizex#&quot;,&quot;^3$&quot;:&quot;#3Sizex#&quot;,&quot;^4$&quot;:&quot;#4Sizex#&quot;,&quot;^5$&quot;:&quot;#5Sizex#&quot;,&quot;^6$&quot;:&quot;#6Sizex#&quot;,&quot;^7$&quot;:&quot;#7Sizex#&quot;,&quot;^8$&quot;:&quot;#8Sizex#&quot;,&quot;^9$&quot;:&quot;#9Sizex#&quot;,&quot;^10$&quot;:&quot;#10Sizex#&quot;<br /><br />&#91;mSizey&#93;<br />Measure=String<br />String=#IN#<br />DynamicVariables=1<br />RegExpSubstitute=1<br />Substitute=&quot;^1$&quot;:&quot;#1Sizey#&quot;,&quot;^2$&quot;:&quot;#2Sizey#&quot;,&quot;^3$&quot;:&quot;#3Sizey#&quot;,&quot;^4$&quot;:&quot;#4Sizey#&quot;,&quot;^5$&quot;:&quot;#5Sizey#&quot;,&quot;^6$&quot;:&quot;#6Sizey#&quot;,&quot;^7$&quot;:&quot;#7Sizey#&quot;,&quot;^8$&quot;:&quot;#8Sizey#&quot;,&quot;^9$&quot;:&quot;#9Sizey#&quot;,&quot;^10$&quot;:&quot;#10Sizey#&quot;<br /><br />&#91;mXMovemt&#93;<br />Measure=String<br />String=#IN#<br />DynamicVariables=1<br />RegExpSubstitute=1<br />Substitute=&quot;^1$&quot;:&quot;#1XMovemt#&quot;,&quot;^2$&quot;:&quot;#2XMovemt#&quot;,&quot;^3$&quot;:&quot;#3XMovemt#&quot;,&quot;^4$&quot;:&quot;#4XMovemt#&quot;,&quot;^5$&quot;:&quot;#5XMovemt#&quot;,&quot;^6$&quot;:&quot;#6XMovemt#&quot;,&quot;^7$&quot;:&quot;#7XMovemt#&quot;,&quot;^8$&quot;:&quot;#8XMovemt#&quot;,&quot;^9$&quot;:&quot;#9XMovemt#&quot;,&quot;^10$&quot;:&quot;#10XMovemt#&quot;<br /><br />&#91;mYMovemt&#93;<br />Measure=String<br />String=#IN#<br />DynamicVariables=1<br />RegExpSubstitute=1<br />Substitute=&quot;^1$&quot;:&quot;#1YMovemt#&quot;,&quot;^2$&quot;:&quot;#2YMovemt#&quot;,&quot;^3$&quot;:&quot;#3YMovemt#&quot;,&quot;^4$&quot;:&quot;#4YMovemt#&quot;,&quot;^5$&quot;:&quot;#5YMovemt#&quot;,&quot;^6$&quot;:&quot;#6YMovemt#&quot;,&quot;^7$&quot;:&quot;#7YMovemt#&quot;,&quot;^8$&quot;:&quot;#8YMovemt#&quot;,&quot;^9$&quot;:&quot;#9YMovemt#&quot;,&quot;^10$&quot;:&quot;#10YMovemt#&quot;<br /><br />&#91;mUpDDiv&#93;<br />Measure=String<br />String=#IN#<br />DynamicVariables=1<br />RegExpSubstitute=1<br />Substitute=&quot;^1$&quot;:&quot;#1UpDDiv#&quot;,&quot;^2$&quot;:&quot;#2UpDDiv#&quot;,&quot;^3$&quot;:&quot;#3UpDDiv#&quot;,&quot;^4$&quot;:&quot;#4UpDDiv#&quot;,&quot;^5$&quot;:&quot;#5UpDDiv#&quot;,&quot;^6$&quot;:&quot;#6UpDDiv#&quot;,&quot;^7$&quot;:&quot;#7UpDDiv#&quot;,&quot;^8$&quot;:&quot;#8UpDDiv#&quot;,&quot;^9$&quot;:&quot;#9UpDDiv#&quot;,&quot;^10$&quot;:&quot;#10UpDDiv#&quot;<br /><br />&#91;MeasureDate&#93;<br />Measure=Time<br />Format=%#m.%d<br />IfCondition=(MeasureDate &gt;= 12.02) &amp;&amp; (MeasureDate &lt;= 12.25)<br />IfTrueAction=&#91;!ShowGroup One&#93;<br />IfFalseAction=&#91;!HideGroup One&#93;<br /><br /><br />&#91;RX&#93;<br />Measure=Calc<br />Formula=Random<br />UpdateRandom=1<br />LowBound=(#Xc#-(&#91;mSizex&#93;+&#91;mXMovemt&#93;))<br />HighBound=(#Xc#+&#91;mXMovemt&#93;)<br />DynamicVariables=1<br />UpdateDivider=&#91;mUpDDiv&#93;<br /><br /><br />&#91;RY&#93;<br />Measure=Calc<br />Formula=Random<br />UpdateRandom=1<br />LowBound=(#Yc#-(&#91;mSizey&#93;+&#91;mYMovemt&#93;))<br />HighBound=(#Yc#+&#91;mYMovemt&#93;)<br />DynamicVariables=1<br />UpdateDivider=&#91;mUpDDiv&#93;<br /><br />&#91;Boo&#93;<br />Meter=Image<br />ImageName=#@#icons\&#91;mIName&#93;<br />x=&#91;RX&#93;<br />Y=&#91;RY&#93;<br />DynamicVariables=1<br />Group=One<br /><br /><br />&#91;SHData&#93;<br />Meter=String<br />x=900<br />y=50<br />FontSize=15<br />FontColor=0,0,0,255<br />Text=Xc=#Xc##CRLF#Yc=#Yc##CRLF#RX=&#91;RX&#93;#CRLF#RY=&#91;RY&#93;#CRLF#Xmovemt=&#91;mXmovemt&#93;#CRLF#YMovemt=&#91;mYMovemt&#93;#CRLF#UpDDivider=&#91;mUpDDiv&#93;#CRLF#&#91;MeasureDate&#93;</code></div></div><p>Statistics: Posted by <a href="http://rainmeter.net/forum/memberlist.php?mode=viewprofile&amp;u=10741">bill98</a> — Today, 7:36 am</p><hr />]]></content>
94
+  </entry>
95
+  <entry>
96
+    <author>
97
+      <name><![CDATA[balala]]></name>
98
+    </author>
99
+    <updated>2015-10-11T05:42:06+00:00</updated>
100
+    <published>2015-10-11T05:42:06+00:00</published>
101
+    <id>http://rainmeter.net/forum/viewtopic.php?t=21980&amp;p=116379#p116379</id>
102
+    <link href="http://rainmeter.net/forum/viewtopic.php?t=21980&amp;p=116379#p116379" />
103
+    <title type="html"><![CDATA[Help: Rainmeter Skins • Re: Lano Visualizer - computer can't auto-sleep]]></title>
104
+    <category term="Help: Rainmeter Skins" scheme="http://rainmeter.net/forum/viewforum.php?f=5" label="Help: Rainmeter Skins" />
105
+    <content type="html" xml:base="http://rainmeter.net/forum/viewtopic.php?t=21980&amp;p=116379#p116379"><![CDATA[I had the same issue a while ago. I also looked for a fix/solution, but found no one. Finaly I stoped using any visualizer skin. But I also would be interested finding a fix, if it's possible. There is one?<p>Statistics: Posted by <a href="http://rainmeter.net/forum/memberlist.php?mode=viewprofile&amp;u=7491">balala</a> — Today, 5:42 am</p><hr />]]></content>
106
+  </entry>
107
+  <entry>
108
+    <author>
109
+      <name><![CDATA[balala]]></name>
110
+    </author>
111
+    <updated>2015-10-11T05:37:02+00:00</updated>
112
+    <published>2015-10-11T05:37:02+00:00</published>
113
+    <id>http://rainmeter.net/forum/viewtopic.php?t=21982&amp;p=116378#p116378</id>
114
+    <link href="http://rainmeter.net/forum/viewtopic.php?t=21982&amp;p=116378#p116378" />
115
+    <title type="html"><![CDATA[Help: Rainmeter Skins • Re: Test if Today is Between 2 Dates]]></title>
116
+    <category term="Help: Rainmeter Skins" scheme="http://rainmeter.net/forum/viewforum.php?f=5" label="Help: Rainmeter Skins" />
117
+    <content type="html" xml:base="http://rainmeter.net/forum/viewtopic.php?t=21982&amp;p=116378#p116378"><![CDATA[Don't use the IfMatch/IfMatchAction/IfNotMatchAction options, instead try with IfConditions. To do that, you have to properly format the date. Instead of the <span style="background: none repeat scroll 0 0 #FFFFFF; border: 1px solid #869AA8; color: #2E8B57; display: inline; font-family: Monaco,'Andale Mono','Courier New',Courier,monospace; font-size: 1em; font-style: normal; line-height: 1.3em; padding: 0 3px;">Format=%m%d</span>, try this format option: <span style="background: none repeat scroll 0 0 #FFFFFF; border: 1px solid #869AA8; color: #2E8B57; display: inline; font-family: Monaco,'Andale Mono','Courier New',Courier,monospace; font-size: 1em; font-style: normal; line-height: 1.3em; padding: 0 3px;">Format=%m.%d</span>. Now you'll have a date formated as a decimal number (eg for today I have right now 10.11). This way you can use the IfConditions:<br /><div><div class="codetitle"><b>Code:</b> </div><div class="codecontent"><code>&#91;MeasureDate&#93;<br />Measure=Time<br />Format=%#m.%d<br />IfCondition=((MeasureDate&gt;=10.01)&amp;&amp;(MeasureDate&lt;=10.09))<br />IfTrueAction=&#91;!ShowGroup One&#93;<br />IfFalseAction=&#91;!HideGroup One&#93;</code></div></div><br />Two other comments about your code:<br />1. I don't think you'd need the <span style="background: none repeat scroll 0 0 #FFFFFF; border: 1px solid #869AA8; color: #2E8B57; display: inline; font-family: Monaco,'Andale Mono','Courier New',Courier,monospace; font-size: 1em; font-style: normal; line-height: 1.3em; padding: 0 3px;">IfConditionMode=1</span>/<span style="background: none repeat scroll 0 0 #FFFFFF; border: 1px solid #869AA8; color: #2E8B57; display: inline; font-family: Monaco,'Andale Mono','Courier New',Courier,monospace; font-size: 1em; font-style: normal; line-height: 1.3em; padding: 0 3px;">IfMatchMode=1</span> option. Without it, the condition will be checked when the date is changing, with it, on every update cycle. It's useless.<br />2. Even if you'd try to use the IfMatch option, in your code that was wrong: you can't use operators (=, &lt; or &gt;), because we're talking about strings.<p>Statistics: Posted by <a href="http://rainmeter.net/forum/memberlist.php?mode=viewprofile&amp;u=7491">balala</a> — Today, 5:37 am</p><hr />]]></content>
118
+  </entry>
119
+  <entry>
120
+    <author>
121
+      <name><![CDATA[bill98]]></name>
122
+    </author>
123
+    <updated>2015-10-11T03:38:51+00:00</updated>
124
+    <published>2015-10-11T03:38:51+00:00</published>
125
+    <id>http://rainmeter.net/forum/viewtopic.php?t=21982&amp;p=116377#p116377</id>
126
+    <link href="http://rainmeter.net/forum/viewtopic.php?t=21982&amp;p=116377#p116377" />
127
+    <title type="html"><![CDATA[Help: Rainmeter Skins • Test if Today is Between 2 Dates]]></title>
128
+    <category term="Help: Rainmeter Skins" scheme="http://rainmeter.net/forum/viewforum.php?f=5" label="Help: Rainmeter Skins" />
129
+    <content type="html" xml:base="http://rainmeter.net/forum/viewtopic.php?t=21982&amp;p=116377#p116377"><![CDATA[Can I do something like this to test if the date is between two dates<br /><br /><br />[MeasureDate]<br />Measure=Time<br />Format=%m%d<br />IfMatch&gt;=1001 &amp;&amp; &lt;=1009<br />IfMatchAction=[!ShowGroup One]<br />IfNotMatchAction=[!HideGroup One]<br />IfMatchMode=1<p>Statistics: Posted by <a href="http://rainmeter.net/forum/memberlist.php?mode=viewprofile&amp;u=10741">bill98</a> — Today, 3:38 am</p><hr />]]></content>
130
+  </entry>
131
+</feed>

+ 35 - 0
spec/models/agents/website_agent_spec.rb

@@ -529,6 +529,41 @@ describe Agents::WebsiteAgent do
529 529
         end
530 530
       end
531 531
 
532
+      describe "XML with cdata" do
533
+        before do
534
+          stub_request(:any, /cdata_rss/).to_return(
535
+            body: File.read(Rails.root.join("spec/data_fixtures/cdata_rss.atom")),
536
+            status: 200
537
+          )
538
+
539
+          @checker = Agents::WebsiteAgent.new(name: 'cdata', options: {
540
+            'name' => 'CDATA',
541
+            'expected_update_period_in_days' => '2',
542
+            'type' => 'xml',
543
+            'url' => 'http://example.com/cdata_rss.atom',
544
+            'mode' => 'on_change',
545
+            'extract' => {
546
+              'author' => { 'xpath' => '/feed/entry/author/name', 'value' => './/text()', 'strip_cdata' => true },
547
+              'title' => { 'xpath' => '/feed/entry/title', 'value' => './/text()', 'strip_cdata' => false },
548
+              'content' => { 'xpath' => '/feed/entry/content', 'value' => './/text()' },
549
+            }
550
+          }, keep_events_for: 2.days)
551
+          @checker.user = users(:bob)
552
+          @checker.save!
553
+        end
554
+
555
+        it "works with XPath" do
556
+          expect {
557
+            @checker.check
558
+          }.to change { Event.count }.by(10)
559
+          event = Event.last
560
+          expect(event.payload['author']).to eq('bill98')
561
+          expect(event.payload['title']).to eq('<![CDATA[Help: Rainmeter Skins • Test if Today is Between 2 Dates]]>')
562
+          expect(event.payload['content']).to start_with('<![CDATA[Can I ')
563
+        end
564
+
565
+      end
566
+
532 567
       describe "JSON" do
533 568
         it "works with paths" do
534 569
           json = {